import { Service } from "cl-admin";
import BaseService from "@/service/base";
import { last } from "cl-admin/utils";

@Service("PreSale")
class PreSale extends BaseService {
	/**
	 * 部门目标列表
	 */
	page({ size, dept_ids = [], bra_id = [], ...args }) {
		// console.log(dept_ids);
		let params = {
			...args,
			dept_ids: dept_ids.join(),
			bra_id: bra_id.join(),
			pagesize: size
		};
		// if (dept_ids && dept_ids.length) {
		// 	params.dept_id = last(dept_ids);
		// }
		return this.$get("/lists", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}

	/**
	 * 文件上传，如果模式是 cloud，返回对应参数
	 *
	 * @returns
	 * @memberof CommonService
	 */
	upload(params) {
		return this.request({
			url: "/upload",
			method: "POST",
			params
		});
	}

	// 售前目标报表
	reportpresale({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()
		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/reportpresale", { params });
	}

	// 目标日跟踪详情
	daytrackDetail(param) {
		return this.$post("/details", param);
	}

	//售前日跟踪底部报表
	detailsReport(params) {
		return this.$get("/detailsReport", { params });
	}

	// 目标日跟踪详情
	targetdaydetail(params) {
		return this.$post("/deptdetailed", params);
	}

	// 修改目标
	edittarget(params) {
		return this.$post("/edit", params);
	}

	// 删除目标
	deltarget(params) {
		return this.$post("/delete", params);
	}

	// 目标组员任务详情
	teamdetails(param) {
		return this.$post("/teamdetails", param);
	}

	//组员目标修改
	teamtargetedit(param) {
		return this.$post("/teamgoalsedit", param);
	}

	//组员目标删除
	teamtargetdel(param) {
		return this.$post("/teamgoalsdelete", param);
	}

	// 添加部门目标
	adddeptarget(param) {
		return this.$post("/add", param);
	}

	// 售前部门报表-部门报表
	presaledepreport({ date = [], dept_ids = [], bra_id = [], ...args }) {
		let params = {
			...args,
			dept_ids: dept_ids.join(),
			bra_id: bra_id.join()

		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// if (dept_ids && dept_ids.length) {
		// 	params.dept_id = last(dept_ids);
		// }
		return this.$get("/reportDept", { params });
	}

	reportDeptTree({ date = [], dept_ids = [], bra_id = [], ...args }) {
		let params = {
			...args,
			dept_ids: dept_ids.join(),
			bra_id: bra_id.join(),
      show_title:1

		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// if (dept_ids && dept_ids.length) {
		// 	params.dept_id = last(dept_ids);
		// }
		return this.$get("/reportDeptTree", { params });
	}

	// 售前部门报表-门店报表
	presalestorerep({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()
		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/reportStore", { params });
	}

	// 售前个人报表-今日报表
	presaleperday({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()

		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/reportPerson", { params });
	}

	// 售前个人报表-本月每日
	presalemonday({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()

		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/reportPersonEachDay", { params });
	}

	//新增组员目标
	addgrouptarhet(param) {
		return this.$post("/teamgoalsadd", param);
	}
}

export default PreSale;
